package com.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.Result;
import com.constants.ResultCode;
import com.pojo.entity.Goods;
import com.pojo.vo.GoodsVo;
import com.service.IGoodsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 商品接口
 *
 * @author : 杨世博
 * @date: Created in 1:52 2023/6/3
 */
@RestController
@RequestMapping("/goods")
@Api(tags = "商品接口")
@Slf4j
public class GoodsController {

    @Autowired
    IGoodsService goodsService;

    /**
     * 查找商品
     * @param goodsKey
     * @param pageNum
     * @param size
     * @return
     */
    @GetMapping("/searchGoods")
    public Result<IPage<GoodsVo>> searchGoods(@RequestParam(value = "goodsKey")String goodsKey,
                                              @RequestParam("pageNum")Integer pageNum,
                                              @RequestParam("size")Integer size){
        IPage<GoodsVo> goods = goodsService.searchGoods(goodsKey, pageNum, size);

        return Result.judge(goods!=null, goods, ResultCode.GOODS_NOT_EXIST);
    }

    /**
     * 推荐商品
     * @return
     */
    @GetMapping("/recommendGoods")
    public Result<List<GoodsVo>> recommendGoods(){
        List<GoodsVo> goods = goodsService.recommendGoods();
        return Result.success(goods);
    }

    @GetMapping("/goodsDetail")
    public Result<Goods> goodsDetail(@RequestParam("id")Integer id){
        Goods goods = goodsService.goodsDetail(id);

        return Result.success(goods);
    }
}
